using System;
using System.Text.RegularExpressions;


namespace miPics.BasePage
{

	public abstract class BaseAdministrationGallery : BasePage
	{
		protected const string GalleryDateFormat = "dd/MM/yyyy";
		private DateTime _ParsedGalleryDate;

		protected void ValidateGalleryDate(string InputDate)
		{
			Regex Regexp = new Regex(@"^(?<day>\d{1,2})/(?<month>\d{1,2})/(?<year>\d{4})$", RegexOptions.IgnoreCase);
			Match Found = Regexp.Match(InputDate);

			if (Found.Success)
			{
				if (!this.CheckDate(Found.Groups["day"].Value, Found.Groups["month"].Value, Found.Groups["year"].Value))
				{
					this.GalleryDateError = "Invalid gallery date value";
				}

				return;
			}

			this.GalleryDateError = "Invalid gallery date format - must be dd/mm/yyyy";
		}
 
		protected string GetNewGalleryDate
		{
			get { return DateTime.Now.ToString(GalleryDateFormat); }
		}

		protected DateTime ParsedGalleryDate
		{
			get { return this._ParsedGalleryDate; }
		}

		private bool CheckDate(string InputDay, string InputMonth, string InputYear)
		{
			return
				DateTime.TryParse(
					string.Format("{0:d}/{1:d}/{2:d} 00:00:00",InputYear,InputMonth,InputDay),
					out this._ParsedGalleryDate);
		}

		protected abstract string GalleryDateError
		{
			set;
		}
	}

}